package com.example.crud.fhys.po;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.TableName;
import com.example.common.util.util_entity.core.BaseEntity;
import java.time.LocalDate;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.function.Function;
import lombok.Data;
import lombok.EqualsAndHashCode;

import static com.example.common.util.list2tree.ListToTreeUtil.buildTree;

/**
 * (ProRecord)表实体类
 *
 * @author zjarlin
 * @since 2023-03-01 13:53:14
 */
@Data
@TableName(value = "fhys_pro_record")
@EqualsAndHashCode(callSuper = true)
public class ProRecord extends BaseEntity {

    private String projectId;

    private String buildingIndex;

    private Integer unitNum;

    private String floorNo;

    private String houseNum;

    private LocalDate tjAcceptanceDate;

    private String tjContent1;

    private String tjContent2;

    private String tjContent3;

    private String tjContent4;

    private String tjContent5;

    private String tjResult;

    private String azContent1;

    private String azContent2;

    private String azContent3;

    private String azContent4;

    private String azContent5;

    private String azContent6;

    private String azContent7;

    private String azResult;

    private String locationImgUrl;

    private LocalDate azAcceptanceDate;

    private String azAcceptancePhase;

    private String tjAcceptancePhase;

    private String wordAttachment;

    private String tjPass1;

    private String tjPass2;

    private String tjPass3;

    private String tjPass4;

    private String tjPass5;

    private String azPass1;

    private String azPass2;

    private String azPass3;

    private String azPass4;

    private String azPass5;

    private String azPass6;

    private String azPass7;

    private String qrCodeRelativeUrl;

    private String azLocationImgUrl;

    private String qrCode;

    private String acceptedIdentification;

    public static void main(String[] args) {
        String s = "[{\"buildingIndex\":\"7\",\"floorNo\":\"01\",\"houseNum\":\"0101\",\"id\":\"1641254291970719745\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":1},{\"buildingIndex\":\"7\",\"floorNo\":\"01\",\"houseNum\":\"0102\",\"id\":\"1641254291983302658\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":1},{\"buildingIndex\":\"7\",\"floorNo\":\"01\",\"houseNum\":\"0103\",\"id\":\"1641254291983302659\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":1},{\"buildingIndex\":\"7\",\"floorNo\":\"01\",\"houseNum\":\"0104\",\"id\":\"1641254291987496961\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":1},{\"buildingIndex\":\"7\",\"floorNo\":\"02\",\"houseNum\":\"0201\",\"id\":\"1641254291991691266\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":1},{\"buildingIndex\":\"7\",\"floorNo\":\"02\",\"houseNum\":\"0202\",\"id\":\"1641254292000079873\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":1},{\"buildingIndex\":\"7\",\"floorNo\":\"02\",\"houseNum\":\"0203\",\"id\":\"1641254292008468481\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":1},{\"buildingIndex\":\"7\",\"floorNo\":\"02\",\"houseNum\":\"0204\",\"id\":\"1641254292025245697\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":1},{\"buildingIndex\":\"7\",\"floorNo\":\"03\",\"houseNum\":\"0302\",\"id\":\"1641254292062994434\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":1},{\"buildingIndex\":\"7\",\"floorNo\":\"03\",\"houseNum\":\"0303\",\"id\":\"1641254292075577345\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":1},{\"buildingIndex\":\"7\",\"floorNo\":\"03\",\"houseNum\":\"0304\",\"id\":\"1641254292079771649\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":1},{\"buildingIndex\":\"7\",\"floorNo\":\"04\",\"houseNum\":\"0402\",\"id\":\"1641254292100743169\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":1},{\"buildingIndex\":\"7\",\"floorNo\":\"04\",\"houseNum\":\"0404\",\"id\":\"1641254292130103297\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":1},{\"buildingIndex\":\"7\",\"floorNo\":\"05\",\"houseNum\":\"0501\",\"id\":\"1641254292130103298\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":1},{\"buildingIndex\":\"7\",\"floorNo\":\"05\",\"houseNum\":\"0504\",\"id\":\"1641254292159463427\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":2},{\"buildingIndex\":\"7\",\"floorNo\":\"01\",\"houseNum\":\"0104\",\"id\":\"1641254292188823554\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":2},{\"buildingIndex\":\"7\",\"floorNo\":\"02\",\"houseNum\":\"0201\",\"id\":\"1641254292197212162\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":2},{\"buildingIndex\":\"7\",\"floorNo\":\"02\",\"houseNum\":\"0202\",\"id\":\"1641254292213989378\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":2},{\"buildingIndex\":\"7\",\"floorNo\":\"02\",\"houseNum\":\"0203\",\"id\":\"1641254292213989379\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":2},{\"buildingIndex\":\"7\",\"floorNo\":\"02\",\"houseNum\":\"0204\",\"id\":\"1641254292226572289\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":2},{\"buildingIndex\":\"7\",\"floorNo\":\"03\",\"houseNum\":\"0301\",\"id\":\"1641254292234960898\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":2},{\"buildingIndex\":\"7\",\"floorNo\":\"03\",\"houseNum\":\"0304\",\"id\":\"1641254292234960901\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":2},{\"buildingIndex\":\"7\",\"floorNo\":\"04\",\"houseNum\":\"0401\",\"id\":\"1641254292234960902\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":2},{\"buildingIndex\":\"7\",\"floorNo\":\"04\",\"houseNum\":\"0402\",\"id\":\"1641254292234960903\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":2},{\"buildingIndex\":\"7\",\"floorNo\":\"04\",\"houseNum\":\"0404\",\"id\":\"1641254292234960905\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":2},{\"buildingIndex\":\"7\",\"floorNo\":\"05\",\"houseNum\":\"0501\",\"id\":\"1641254292251738113\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":2},{\"buildingIndex\":\"7\",\"floorNo\":\"05\",\"houseNum\":\"0503\",\"id\":\"1641254292260126722\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":2},{\"buildingIndex\":\"7\",\"floorNo\":\"05\",\"houseNum\":\"0504\",\"id\":\"1641254292268515330\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":2},{\"buildingIndex\":\"7\",\"floorNo\":\"01\",\"houseNum\":\"0101\",\"id\":\"1641254292268515331\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":3},{\"buildingIndex\":\"7\",\"floorNo\":\"01\",\"houseNum\":\"0104\",\"id\":\"1641254292302069761\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":3},{\"buildingIndex\":\"7\",\"floorNo\":\"02\",\"houseNum\":\"0201\",\"id\":\"1641254292306264065\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":3},{\"buildingIndex\":\"7\",\"floorNo\":\"02\",\"houseNum\":\"0202\",\"id\":\"1641254292310458370\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":3},{\"buildingIndex\":\"7\",\"floorNo\":\"02\",\"houseNum\":\"0203\",\"id\":\"1641254292318846978\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":3},{\"buildingIndex\":\"7\",\"floorNo\":\"03\",\"houseNum\":\"0301\",\"id\":\"1641254292327235586\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":3},{\"buildingIndex\":\"7\",\"floorNo\":\"03\",\"houseNum\":\"0302\",\"id\":\"1641254292335624194\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":3},{\"buildingIndex\":\"7\",\"floorNo\":\"03\",\"houseNum\":\"0303\",\"id\":\"1641254292339818498\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":3},{\"buildingIndex\":\"7\",\"floorNo\":\"03\",\"houseNum\":\"0304\",\"id\":\"1641254292348207105\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":3},{\"buildingIndex\":\"7\",\"floorNo\":\"04\",\"houseNum\":\"0401\",\"id\":\"1641254292352401410\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":3},{\"buildingIndex\":\"7\",\"floorNo\":\"04\",\"houseNum\":\"0403\",\"id\":\"1641254292360790017\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":3},{\"buildingIndex\":\"7\",\"floorNo\":\"05\",\"houseNum\":\"0501\",\"id\":\"1641254292373372930\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":3},{\"buildingIndex\":\"7\",\"floorNo\":\"05\",\"houseNum\":\"0502\",\"id\":\"1641254292373372931\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":3},{\"buildingIndex\":\"7\",\"floorNo\":\"05\",\"houseNum\":\"0504\",\"id\":\"1641254292385955841\",\"projectId\":\"1641254290985058305\",\"qrCode\":\"\",\"unitNum\":3}]\n";

        List<ProRecord> proRecords = JSON.parseArray(s, ProRecord.class);
        LinkedHashMap<String, Function<ProRecord, ?>> linkedHashMap = new LinkedHashMap<String, Function<ProRecord, ?>>() {{

            //指定多个分组节点
            //楼节点
            put("projectBuildingNumberLinkNode", fhysProRecord -> fhysProRecord.getBuildingIndex() + "号楼");
            //单元节点
            put("unitNode", ProRecord::getUnitNum);
            //层节点
            put("layerNode", ProRecord::getFloorNo);
            //户节点
            put("householdNode", ProRecord::getHouseNum);
        }};
        //最里层的数据只要id
        List<JSONObject> jsonObjects = buildTree(proRecords, linkedHashMap, ProRecord::getId);

        System.out.println(JSON.toJSONString(jsonObjects));
    }

}
